package views;

import DAO.ProfesorDao;
import views.panels.PanelGeneral;
import java.awt.BorderLayout;
import java.util.Collection;
import java.util.Iterator;
import models.Profesor;

/**
 *
 * @author viviana
 */
public class InterfazConsultarHV extends javax.swing.JFrame {

    /** Creates new form InterfazConsultarHV */
    public InterfazConsultarHV() {
        initComponents();
        PanelGeneral panel = new PanelGeneral();
        this.add(panel, BorderLayout.SOUTH);
        inicializarComboBox();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        CBSelectProfe = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        CTEdad = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        CTGenero = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        CTTelFijo = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        CTTelMovil = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        CTDireccion = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        CTFechaNacimiento = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        CTNomUsuario = new javax.swing.JTextField();
        BAceptar = new javax.swing.JButton();

        setResizable(false);

        jLabel1.setText("Seleccione documento del Profesor:");

        CBSelectProfe.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione" }));
        CBSelectProfe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBSelectProfeActionPerformed(evt);
            }
        });

        jLabel2.setText("Nombres y apellidos");

        jTextField1.setEditable(false);

        jLabel3.setText("Edad");

        CTEdad.setEditable(false);

        jLabel4.setText("Especialidad:");

        jTextField3.setEditable(false);

        jLabel5.setText("Género:");

        CTGenero.setEditable(false);

        jLabel6.setText("Teléfono Fijo");

        CTTelFijo.setEditable(false);

        jLabel7.setText("Teléfono Móvil");

        CTTelMovil.setEditable(false);

        jLabel8.setText("Dirección:");

        CTDireccion.setEditable(false);

        jLabel9.setText("Fecha de Nacimiento:");

        CTFechaNacimiento.setEditable(false);

        jLabel10.setText("Nombre de Usuario:");

        CTNomUsuario.setEditable(false);

        BAceptar.setFont(new java.awt.Font("Tahoma", 1, 11));
        BAceptar.setText("Aceptar");
        BAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(CTFechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel10)
                                .addGap(18, 18, 18)
                                .addComponent(CTNomUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(CTDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, 569, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(CTGenero, javax.swing.GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel6)
                                .addGap(18, 18, 18)
                                .addComponent(CTTelFijo, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel7)
                                .addGap(18, 18, 18)
                                .addComponent(CTTelMovil, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 569, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel3)
                                .addGap(18, 18, 18)
                                .addComponent(CTEdad, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE))
                            .addComponent(CBSelectProfe, javax.swing.GroupLayout.Alignment.TRAILING, 0, 569, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(BAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(245, 245, 245))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CBSelectProfe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CTEdad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(CTTelMovil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(CTTelFijo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(CTGenero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6))
                    .addComponent(jLabel7))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(CTDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(CTFechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CTNomUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addGap(18, 18, 18)
                .addComponent(BAceptar)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BAceptarActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_BAceptarActionPerformed

    private void CBSelectProfeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBSelectProfeActionPerformed
        if (CBSelectProfe.getSelectedIndex() <= 0){
            jTextField1.setText("");
            CTDireccion.setText("");
            CTEdad.setText("");
            CTFechaNacimiento.setText("");
            CTGenero.setText("");
            CTNomUsuario.setText("");
            CTTelFijo.setText("");
            CTTelMovil.setText("");
            jTextField3.setText("");
        }
        else{
            ProfesorDao profesorDao = new ProfesorDao();
            Collection profesores = profesorDao.encontrarProfesores();
            Profesor profesor = null;
            for (Iterator it = profesores.iterator(); it.hasNext();) {
                Profesor prof = (Profesor) it.next();
                if (CBSelectProfe.getSelectedItem().equals(prof.getDocprofesor())){
                    profesor = prof;
                }
            }
            jTextField1.setText(profesor.getNombresprofesor() + " " +
                    profesor.getApellidosprofesor());
            CTDireccion.setText(profesor.getDireccionprof());
            CTEdad.setText(String.valueOf(profesor.getEdadprof()));
            CTFechaNacimiento.setText(profesor.getFechanacimientoprof());
            CTGenero.setText(profesor.getGeneroprof());
            CTNomUsuario.setText(profesor.getUsuarioId().getNombreUsuario());
            if (profesor.getTelefonosId().getTipoTelefono().equals("fijo")){
                CTTelFijo.setText(profesor.getTelefonosId().getTelefono());
            }
            else{
                CTTelMovil.setText(profesor.getTelefonosId().getTelefono());
            }
            jTextField3.setText(profesor.getEspecialidad());
        }
    }//GEN-LAST:event_CBSelectProfeActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InterfazConsultarHV().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BAceptar;
    private javax.swing.JComboBox CBSelectProfe;
    private javax.swing.JTextField CTDireccion;
    private javax.swing.JTextField CTEdad;
    private javax.swing.JTextField CTFechaNacimiento;
    private javax.swing.JTextField CTGenero;
    private javax.swing.JTextField CTNomUsuario;
    private javax.swing.JTextField CTTelFijo;
    private javax.swing.JTextField CTTelMovil;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration//GEN-END:variables

    private void inicializarComboBox() {
        ProfesorDao profesorDao = new ProfesorDao();
        Collection profesores = profesorDao.encontrarProfesores();
        for (Iterator it = profesores.iterator(); it.hasNext();) {
            Profesor profesor = (Profesor) it.next();
            CBSelectProfe.addItem(profesor.getDocprofesor());
        }
    }
}
